package org.csu.mypetstore.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.csu.mypetstore.commonResponse.CommonResponse;
import org.csu.mypetstore.domin.Account;
import org.csu.mypetstore.domin.Address;
import org.csu.mypetstore.domin.Category;
import org.csu.mypetstore.persistence.CategoryMapper;
import org.csu.mypetstore.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("CategoryService")
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;


    //获得Category列表
    @Override
    public CommonResponse<List<Category>> getCategoryList() {

        List<Category> categoryList = categoryMapper.selectList(null);
        if(categoryList==null){
            return CommonResponse.createForError("获取商品信息失败");
        }else{
            return CommonResponse.createForSuccess("查找成功",categoryList);
        }

    }

    //获得Category
    @Override
    public CommonResponse<Category> getCategory(String categoryId) {
        QueryWrapper<Category> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("catid",categoryId);

        Category category=categoryMapper.selectOne(queryWrapper);
        if(categoryId==null){
            return CommonResponse.createForError("通过categoryId无法查找商品信息");
        }
        return CommonResponse.createForSuccess("查找成功",category);
    }
}
